package com.duobaoyu.dby.supply.api.controller;

import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.common.security.annotation.Inner;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceApiClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.bo.MappingBO;
import com.duobaoyu.dby.supply.common.biz.remote.to.config.MappingTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 映射管理
 * @Description
 * @Author liyang
 **/
@Inner
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/state-info")
public class StateInfoController {

    private final ResourceApiClient resourceApiClient;

    @GetMapping(value = "/state")
    public R<List<MappingTO>> getState(@RequestParam("stateCode") String stateCode, String label, Boolean ifDeprecated) {
        List<MappingBO> stateMappings = resourceApiClient.getState(stateCode, label, ifDeprecated);
        return R.ok(stateMappings.stream()
                .map(mapping -> MappingTO.builder()
                        .value(mapping.getValue())
                        .name(mapping.getName())
                        .additional(mapping.getAdditional())
                        .build())
                .collect(Collectors.toList()));
    }
}
